<?php get_header(); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <?php
    if ($post->post_parent): $postParent = get_post($post->post_parent); endif;
  ?>
<?php if (get_field('color_class', $post)): ?>
<div class="intro <?php the_field('color_class', $post) ?>">
  <div class="center-holder">
    <div class="center-frame">
      <div class="intro-area">
        <h6><?php the_field('title', $post); ?></h6>
        <?php $image = get_field('image', $post); ?>
        <img alt="<?php the_field('title', $post); ?>" src="<?php echo $image['url']; ?>">
      </div>
    </div>
  </div>
</div>
<?php elseif (get_field('color_class', $postParent)): ?>
<div class="intro <?php the_field('color_class', $postParent) ?>">
  <div class="center-holder">
    <div class="center-frame">
      <div class="intro-area">
        <h6><?php the_field('title', $postParent); ?></h6>
        <?php $image = get_field('image', $postParent); ?>
        <img alt="<?php the_field('title', $postParent); ?>" src="<?php echo $image['url']; ?>">
      </div>
    </div>
  </div>
</div>
<?php
    endif;
  endwhile;
endif;
?>

<div id="main">
  <div class="main-holder">
    <div class="main-frame">
    <?php if (!is_home()) : ?>
    <div class="breadcrumbs">
      <?php if(function_exists('bcn_display'))
      {
        bcn_display();
      }?>
    </div>
    <?php endif; ?> 
    <div class="content-area">
      <div class="content-holder">
        <div class="content-frame">
          <?php if (have_posts() && !get_field('show_child_pages', $post)): // trang có gellery và sidebar danh sách trang ?>
            <div id="content">
              <?php if (have_rows('gallery_details', get_the_ID())) :?>
              <h1><?php the_title(); ?></h1>
              <div class="gallery-block paused">
                <!-- gallery-fade -->
                <div class="gallery-fade">
                  <ul>
                    <?php $i = 1; while (has_sub_field('gallery_details')) :
                      $image = get_sub_field('image');?>
                      <li <?php if ($i == 1): echo 'class="active" style="display: list-item;"'; else: echo 'style="display: none;"'; endif; ?>><img width="600" height="295" src="<?php echo $image['url']; ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>"></li>
                    <?php $i++; endwhile; ?>
                  </ul>
                  <span class="mask-lt"></span>
                  <span class="mask-rt"></span>
                  <span class="mask-lb"></span>
                  <span class="mask-rb"></span>
                </div>
                <!-- small-gallery -->
                <div class="small-gallery">
                  <a href="#" class="prev">prev</a>
                  <div class="mask">
                    <ul>
                    <?php $i = 1; while (has_sub_field('gallery_details')) :
                      $image = get_sub_field('image');?>
                      <li <?php if ($i == 1): echo ' class="active first"'; endif; ?>>
                        <a href="#"><img width="77" height="52" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" src="<?php echo $image['url']; ?>"></a>
                        <span class="mask-lt"></span>
                        <span class="mask-rt"></span>
                        <span class="mask-lb"></span>
                        <span class="mask-rb"></span>
                      </li>
                    <?php $i++; endwhile; ?>
                    </ul>
                   </div>
                   <a href="#" class="next">next</a>
                 </div>
               </div>
              <div class="description"><?php the_content(); ?></div>
              <div class="btn-holder">
                <a class="btn-red" href="<?php echo site_url(); ?>/request-quote"><span>Request A Quote</span></a>
              </div>
              <?php else: ?>
              <?php the_content(); ?>
              <?php endif; ?>
            </div>
          <?php elseif(have_posts() && get_field('show_child_pages', $post)): // show child page list ?>
          <?php
              $my_wp_query = new WP_Query();
              $all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
              $portfolio_children = get_page_children( get_the_ID(), $all_wp_pages );
              //echo '<pre>' . print_r( $portfolio_children, true ) . '</pre>';
              ?>
            <div class="content-txt">
              <ul class="product-list">
                <?php if ($portfolio_children): ?>
                <?php foreach ($portfolio_children as $child): ?>
                <li>
                  <h2><a href="<?php echo get_page_link($child->ID);?>" title="<?php echo $child->post_title ?>"><?php echo $child->post_title ?></a></h2>
                  <?php
                    $feat_image = wp_get_attachment_url(get_post_thumbnail_id($child->ID));
                    if ($feat_image):
                  ?>
                  <img width="200" height="124" title="<?php echo $child->post_title ?>" alt="<?php echo $child->post_title ?>" src="<?php echo $feat_image ?>">
                  <?php endif;?>
                  <p></p>
                  <div class="btn-row">
                    <a href="<?php echo get_page_link($child->ID);?>" title="<?php echo $child->post_title ?>" class="btn-red"><span>Details</span></a>
                    <a href="<?php echo site_url(); ?>/request-quote" class="btn-grey"><span>Request Quote</span></a>
                  </div>
                </li>
                <?php endforeach; ?>
                <?php endif;?>
              </ul>
            </div>
          <?php endif; ?>
          <?php if ( is_active_sidebar( 'side-bar' ) && !get_field('show_child_pages', $post) ) : ?>
          <div class="aside">
            <?php dynamic_sidebar( 'side-bar' ); ?>
          </div>
          <?php endif; ?>
        </div>
      </div>
    </div>
<?php get_footer(); 
